<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="所属平台：">
          <!-- <city-select v-model="formInline.cities"></city-select> -->
          <platform-select v-model="formInline.platforms"></platform-select>
        </el-form-item>
        <el-form-item label="预约医院：">
          <!-- <el-select v-model="formInline.isAppointmentOpened" clearable>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select> -->
          <hospital-select v-model="formInline.hospitals"></hospital-select>
        </el-form-item>
        <el-form-item label="预约医生：">
          <DoctorSelect v-model="formInline.doctors"></DoctorSelect>
        </el-form-item>
        <el-form-item label="预约商品：">
          <GoodsSelect v-model="formInline.goods"></GoodsSelect>
        </el-form-item>
        <el-form-item label="下单时间：">
          <el-date-picker v-model="formInline.orderTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="关键词：">
          <el-input v-model="formInline.term" placeholder="请输入关键词"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="onSearch">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <!-- 操作区域 开始 -->
      <div class="action_box">
        <el-button type="primary" size="small" :loading="eloading" @click="downloadExcel">筛选结果导出</el-button>
      </div>
      <!-- 操作区域 end -->

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="hospitalName" label="预约医院" show-overflow-tooltip />
        <el-table-column prop="doctorName" label="医生" show-overflow-tooltip />
        <el-table-column prop="goodsName" label="商品" show-overflow-tooltip />
        <el-table-column prop="platform" label="所属平台" show-overflow-tooltip />
        <el-table-column prop="name" label="姓名" show-overflow-tooltip />
        <el-table-column prop="phone" label="手机" show-overflow-tooltip />
        <el-table-column prop="leaveWord" label="留言" show-overflow-tooltip />
        <el-table-column prop="createdDate" label="下单时间" show-overflow-tooltip />
        <el-table-column prop="ip" label="下单ip" show-overflow-tooltip />
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->
  </div>
</template>

<script>
import { showToast, showModal, deepClone } from "@/common/util";
import { GET_APPOINTMENT_SEARCH, DOWNLOAD_APPOINTMENT_EXPORT } from '@/http/consumer'
import DoctorSelect from '@/components/select/doctor.vue'
import GoodsSelect from '@/components/select/goods.vue'
export default {
  components:{
    DoctorSelect,
    GoodsSelect
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      loading: false,
      eloading: false
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = deepClone(this.formInline);
      let m = oParams.orderTime || []
      if(m && m.length){
        oParams.appointmentBeginTime = m[0]
        oParams.appointmentEndTime = m[1]
      }
      delete oParams.orderTime
      oParams.pageNumber = this.pageNumber;
      oParams.pageSize = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GET_APPOINTMENT_SEARCH(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 导出excel
    downloadExcel() {
      let _this = this;
      let o = deepClone(_this.formInline);
      let m = Object.keys(o);
      if (m.length > 0) {
        showModal({
          message: "确定是否导出筛选条件下面所有在线预约列表?",
          showCancelButton: true,
          type: "warning",
          success: function () {
            _this.dowloadExcelFile();
          },
        });
        return false;
      }
      showToast({
        message: "请选择筛选条件后再导出",
      });
      //_this.dowloadExcelFile();
    },

    // 下载excel
    dowloadExcelFile() {
      let _this = this;
      let oParams = _this.getParams();
      let options = {};

      delete oParams.pageNumber;
      delete oParams.pageSize;

      options.method = "GET";
      options.data = oParams;
      options.url = DOWNLOAD_APPOINTMENT_EXPORT;
      options.fileName = "在线预约列表.xlsx";
      _this.eloading = true;
      _this.$exportExcel(options).then((res) => {
        _this.eloading = false;
      });
    },

    // 搜索
    onSearch(){
      this.pageNumber = 1;
      this.getList()
    }
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";
</style>
